package models;

import mvc.MainClass;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Артемка
 * Date: 13.12.13
 * Time: 16:00
 * To change this template use File | Settings | File Templates.
 */
public class Model implements Serializable {
    private ArrayList<Student> studentList;
    private ArrayList<Group> groupList;

    public Model() {
        this.studentList = new ArrayList<Student>();
        this.groupList = new ArrayList<Group>();
    }

    List<ActionListener> groupListeners = new ArrayList<ActionListener>();
    List<ActionListener> studentListeners = new ArrayList<ActionListener>();


    /*public Model(Student student) {
     this.student=student;
    }

    public Model(Group group) {
        this.group=group;
    }*/

    public void addStudent(Student student) {
        studentList.add(student);
        notifyObservers();

    }

    public void removeStudent(Student student) {
        studentList.remove(student);
        notifyObservers();

    }

    private void notifyObservers() {
        for (ActionListener listener : studentListeners) {
            listener.actionPerformed(new ActionEvent(this, 1, "12313"));
        }
    }


    public ArrayList<Student> getStudentList() {

        return this.studentList;
    }

    public ArrayList<Group> getGroupList() {
        return this.groupList;
    }

    public void addListener(ActionListener listener) {
        studentListeners.add(listener);
    }


}
